<?php
/**
 * Access control logic.
 *
 * @category Zend
 * @package Disputeo
 * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc.
 * @version $Id$
 * @link http://framework.zend.com
 * @since Available since release 1.0
 * @license GPL v3
 */

class Disputeo_Acl
{
    const ADMIN = 'admin';
    const MEMBER = 'member';
    const GUEST = 'guest';
    
    /**
     * @var Zend_Acl
     */
    protected $_acl;
    
    /**
     * @var $obj Disputeo_Acl
     */
    protected static $_instance;
    
    /**
     * Initialise ACL properties
     */
    protected function __construct()
    {
        $this->_acl = new Zend_Acl();
        $this->_initRoles();
        $this->_initResources();
        $this->_initPrivilages();
        
        Zend_Registry::set('acl', $this->_acl);
    }
    
    /**
     * ACL roles
     */
    protected function _initRoles()
    {
        $this->_acl->addRole(new Zend_Acl_Role(self::GUEST))
            ->addRole(new Zend_Acl_Role(self::MEMBER))
            ->addRole(new Zend_Acl_Role(self::ADMIN));
    }
    
    /**
     * ACL resources
     */
    protected function _initResources()
    {
        $this->acl->add(new Zend_Acl_Resource('admin'));
    }
    
    /**
     * ACL privilages
     */
    protected function _initPrivilages()
    {
        $this->acl->allow('admin');
    }
    
    /**
     * Magic get method for acl property
     *
     * @param string $name 
     */
    public function __get($name)
    {
        if ($name == 'acl') {
            return $this->_acl;
        }
        
        return null;
    }
    
    /**
     * Get instance of this class
     * 
     * @return Disputeo_Acl
     */
    public static function build()
    {
        if (! self::$_instance) {
            self::$_instance = new self();
        }

        return self::$_instance;
    }
}